<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/public.css}">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" th:value="${classroomVO.id}" class="layui-input">
    <div class="layui-form-item">
        <label class="layui-form-label">教学楼</label>
        <div class="layui-input-block">
            <select name="academicCode" lay-verify="required">
                <option th:each="academic : ${academics}"
                        th:text="${academic.academic_name}" th:value="${academic.academic_code}"
                        th:selected="${academic.academic_name} eq ${classroomVO.academicName}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">教室代码</label>
        <div class="layui-input-block">
            <input type="text" name="classroomCode" th:value="${classroomVO.classroomCode}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">教室名称</label>
        <div class="layui-input-block">
            <input type="text" name="classroomName" th:value="${classroomVO.classroomName}"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">教室类型</label>
        <div class="layui-input-block">
            <select name="classroomTypeId" lay-verify="required">
                <option th:each="classroomType : ${classroomTypes}" th:text="${classroomType.typeName}"
                        th:value="${classroomType.id}" th:selected="${classroomType.typeName} eq ${classroomVO.typeName}"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        // 监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/classroom/put',
                method: 'POST',
                data: data.field,
                success:function (res) {
                    if (res.code == 0 ){
                        layer.msg("保存成功")
                        setTimeout(function () {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        },1500)
                    }else {
                        layer.msg("保存失败")
                    }
                }
            })
            return false;
        });

    });
</script>
</body>
</html>